trigger bINS_bUPD_AgencyTeam on Account (before insert, before update) {
    List<Agency_Team__c> agt = new List<Agency_Team__c>();
    Set<Id> accIds = new Set<Id>();
    try{
        for(Integer i=0; i<Trigger.new.size(); i++){
            accIds.add(Trigger.new[i].Id);
            Agency_Team__c objAGT = new Agency_Team__c();
            objAGT.Account__c = Trigger.new[i].id;
            if(Trigger.new[i].Status__c == 'Stage 1' || Trigger.new[i].Status__c == 'Stage 2'){
                objAGT.Status__c = Trigger.new[i].Status__c;
            }
                   
            agt.add(objAGT);
        }
        if(Trigger.isUpdate){
            Agency_Team__c[] agtDel = [Select Id from Agency_Team__c where Account__c in: accIds];
            System.debug('*********'+agtDel.size()+'-----'+accIds.size());
            delete(agtDel); 
        }
        insert(agt);
    }
    catch(Exception mex){
//        Trigger.new[0].addError(mex.getMessage()+'helloooooooo');
        //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, 'my excepyion message'));
    }
    
}